package com.paopao.domain;


import com.fasterxml.jackson.annotation.JsonRawValue;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import java.util.HashMap;
import java.util.Map;

@JsonSerialize(include=JsonSerialize.Inclusion.NON_NULL)
public class R
{
	static private final Map<Integer, String> map = new HashMap<Integer, String>()
	{{
		put(SUCESS,                     "OK");
	    put(ERROR, 						"ERROR");
	    put(CUSTOM_CODE, 				"");
	}};

	public static final int SUCESS = 200;
	
	//数据库操作失败
	public static final int SQL_OPERATION_ERROR = 0;
	
	public static final int ERROR =					-1; 	// 未知错误
	public static final int CUSTOM_CODE = 			-800; 	// 自定义错误code



    public static String note;

	static public R get(int code)
	{
		return new R(code, map.get(code));
	}
	
	static public R get(int code, String remark) {
		return new R(code, map.get(code), remark);
	}

	private int code;

	private String msg;
	//透传协议修改之后  给前端的回包会添加反斜杠 导致结构异常  加此注解解决问题
	@JsonRawValue
	private String remark;

	private EmployeeBean employeeBean;

	private ItemInfoBean itemInfoBean;

	private ObjectListResult objectListResult;

	public R(int code, String msg, ObjectListResult objectListResult) {
		this.code = code;
		this.msg = msg;
		this.objectListResult = objectListResult;
	}

	public R(int code, String msg, EmployeeBean employeeBean) {
		this.code = code;
		this.msg = msg;
		this.employeeBean = employeeBean;
	}

	public R(int code, String msg, ItemInfoBean itemInfoBean) {
		this.code = code;
		this.msg = msg;
		this.itemInfoBean = itemInfoBean;
	}



	public R(int code, String msg){
		this.code = code;
		this.msg = msg;
	}
	
	public R(int code, String msg, String remark) {
		this.code = code;
		this.msg = msg;
		this.remark = remark;
	}
	
	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public EmployeeBean getEmployeeBean() {
		return employeeBean;
	}

	public void setEmployeeBean(EmployeeBean employeeBean) {
		this.employeeBean = employeeBean;
	}

	public ItemInfoBean getItemInfoBean() {
		return itemInfoBean;
	}

	public void setItemInfoBean(ItemInfoBean itemInfoBean) {
		this.itemInfoBean = itemInfoBean;
	}

	public ObjectListResult getObjectListResult() {
		return objectListResult;
	}

	public void setObjectListResult(ObjectListResult objectListResult) {
		this.objectListResult = objectListResult;
	}
}
